package net.heri.xmppchat.activities.contactlist;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import net.heri.xmppchat.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.QuickContactBadge;
import android.widget.TextView;

import com.google.inject.Inject;

public class ContactListAdapter extends BaseAdapter implements Filterable {
	
	private	Context				mContext;
	private List<String>		mContainerList;
	private List<String>		mDisplayList;
	
	@Inject
	private ContactListFilter	mFilter;
	
	
	// Listview Data
    String products[] = {	"Dell Inspiron", "HTC One X", "HTC Wildfire S", "HTC Sense", "HTC Sensation XE",
    						"iPhone 4S", "Samsung Galaxy Note 800",
    						"Samsung Galaxy S3", "MacBook Air", "Mac Mini", "MacBook Pro"};
	
	@Inject
	public ContactListAdapter(Context context) {
		this.mContext = context;
		this.mContainerList = new ArrayList<String>(Arrays.asList(products) );
		this.mDisplayList = this.mContainerList;
	}
	
	@Override
	public int getCount() {
		return mDisplayList.size();
	}
	
	@Override
	public Object getItem(int position) {
		return mDisplayList.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		return 0;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String item = this.mDisplayList.get(position);
		
		ViewHolder holder; 
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.contact_list_contact_row, parent, false);
			holder.mContactBadge = (QuickContactBadge) convertView.findViewById(R.id.contact_badge);
			holder.mTxtContactName = (TextView) convertView.findViewById(R.id.txt_contact_name);
			holder.mTxtContactStatus = (TextView) convertView.findViewById(R.id.txt_contact_status);
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.mTxtContactName.setText(item);
		holder.mTxtContactStatus.setText("ini status");
		
		return convertView;
	}
	
	@Override
	public Filter getFilter() {
		return this.mFilter;
	}
	
	public void add(String participant) {
		getContainerList().add(participant);
	}
	
	// ----------------------------------------	//
	//	I N N E R  	C L A S S					//
	// ----------------------------------------	//
	
	/**
	 * 
	 */
	private static class ViewHolder {
		QuickContactBadge	mContactBadge;
		TextView 			mTxtContactName;
		TextView 			mTxtContactStatus;
	}
	
	// ----------------------------------------	//
	//	S E T T E R   G E T T E R				//
	// ----------------------------------------	//
	
	public Context getContext() {
		return mContext;
	}
	
	public List<String> getContainerList() {
		return mContainerList;
	}
	
	public void setDisplayList(List<String> list) {
		this.mDisplayList = list;
	}
	
}
